package com.itheima;

import org.junit.jupiter.api.Test;

public class testThreadLocal {

    @Test
    public void testThreadLocalSetAndGet() {
//        提供一个TheadLocal
        ThreadLocal tl = new ThreadLocal();
//        开启两个线程
        new Thread(() -> {
            tl.set("萧炎");
            System.out.println(Thread.currentThread().getName() + ": " +tl.get());
            System.out.println(Thread.currentThread().getName() + ": " +tl.get());
            System.out.println(Thread.currentThread().getName() + ": " +tl.get());
        },"蓝色").start();

        new Thread(() -> {
            tl.set("药尘");
            System.out.println(Thread.currentThread().getName() + ": " +tl.get());
            System.out.println(Thread.currentThread().getName() + ": " +tl.get());
            System.out.println(Thread.currentThread().getName() + ": " +tl.get());
        },"绿色").start();
    }
}

